#include <iostream>
#include <queue>
#include <vector>
using namespace std;

const int kMaxN = 2e5 + 10;
const int kMaxM = 2e5 + 10;

int val[kMaxN], fa[kMaxN], sum[kMaxN];
int e_u[kMaxM], e_v[kMaxM];
vector<int> g[kMaxN];
int id[kMaxN], dp[kMaxN];

int GetFather(int x) {
  if (fa[x] == x) {
    return fa[x];
  }
  return fa[x] = GetFather(fa[x]);
}

void Merge(int x, int y) {
  x = GetFather(x);
  y = GetFather(y);
  if (x != y) {
    if (sum[x] > sum[y]) {
      fa[y] = x;
      sum[x] += sum[y];
    } else {
      fa[x] = y;
      sum[y] += sum[x];
    }
  }
}

int GetLongestPath(int n) {
  queue<int> q;

  for (int i = 1; i <= n; i++) {
    dp[i] = -kMaxN;
    if (id[i] == 0) {
      q.emplace(i);
    }
  }
  dp[GetFather(1)] = 1;
  while (!q.empty()) {
    int u = q.front();

    q.pop();
    for (int v : g[u]) {
      id[v]--;
      dp[v] = max(dp[u] + 1, dp[v]);
      if (id[v] == 0) {
        q.emplace(v);
      }
    }
  }
  return dp[GetFather(n)] < 0 ? 0 : dp[GetFather(n)];
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> val[i];
    fa[i] = i;
    sum[i] = 1;
  }
  int tot = 0;
  for (int i = 0; i < m; i++) {
    cin >> e_u[tot] >> e_v[tot];
    if (val[e_u[tot]] == val[e_v[tot]]) {
      Merge(e_u[tot], e_v[tot]);
    } else {
      tot++;
    }
  }

  for (int i = 0; i < tot; i++) {
    int u = GetFather(e_u[i]), v = GetFather(e_v[i]);

    if (val[u] > val[v]) {
      swap(u, v);
    }
    g[u].emplace_back(v);
    id[v]++;
  }
  cout << GetLongestPath(n) << "\n";
  return 0;
}